package com.xwdeshj.controller;

import org.junit.Test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * Created by BKWJA on 2018/11/20.
 */
public class CreateFile {

    //根据当前日期创建文件夹
    @Test
    public void createFile(){

        Date date = new Date();
        String path="E:/"+new SimpleDateFormat("yyyy-MM-dd").format(date);
        //如果不存在,创建文件夹
        File f = new File(path);
        if(!f.exists()){
            f.mkdirs();
        }
        OutputStream out;
        UUID uuid = UUID.randomUUID(); //随机名称
        String fileName = uuid + ".txt";
        try {
            out = new FileOutputStream(path + fileName);
            out.flush();
            out.close();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
